//
//  ApiResponse.m
//  ScoutIOS
//
//  Created by bigknife on 13-9-6.
//  Copyright (c) 2013年 bigknife. All rights reserved.
//

#import "ApiResponse.h"
#import "VMCMacros.h"

@implementation ApiResponse
@synthesize requestId = _requestId;
@synthesize success = _success;
@synthesize code = _code;
@synthesize msg = _msg;
@synthesize info = _info;
@synthesize sign = _sign;
@synthesize responseTime = _responseTime;
@synthesize token = _token;

- (id)initWithDictionary:(NSDictionary *)dictionary {
    if (!self) {
        self = [[ApiResponse alloc] init];
    }
	if([[dictionary allKeys] containsObject:@"msg_code"]){
		NSString *msgCode = [dictionary objectForKey:@"msg_code"];
		if(msgCode != (id) [NSNull null]){
			self.code = [msgCode intValue];
			//NSLog(@"%d",self.code);
		}

	}

	if ([[dictionary allKeys] containsObject:@"msg"]) {
		self.msg = [dictionary objectForKey:@"msg"];
	}
	if ([[dictionary allKeys] containsObject:@"responseTime"]) {
		self.responseTime = [[dictionary objectForKey:@"responseTime"] longValue];
	}
	if ([[dictionary allKeys] containsObject:@"sign"]) {
		self.sign = [dictionary objectForKey:@"sign"];
	}
	if ([[dictionary allKeys] containsObject:@"requestId"]) {
		self.requestId = [dictionary objectForKey:@"requestId"];
	}
	if ([[dictionary allKeys] containsObject:@"result"]) {
		self.success = [[dictionary objectForKey:@"result"] isEqual:@"success"];
	}
	if ([[dictionary allKeys] containsObject:@"info"]) {
		self.info = [dictionary objectForKey:@"info"];
	}
	if ([[dictionary allKeys] containsObject:@"session"]) {
		self.token = [dictionary objectForKey:@"session"];
	}
	return self;
}


- (NSString *)msg {
	if(_msg == (id) [NSNull null]){
		return nil;
	}
	return _msg;
}

@end
